<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- default_extensionfactory.cpp -->
  <title>QExtensionFactory Class | Qt Designer Manual</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.14</a></td><td ><a href="qtdesigner-manual.html">Qt Designer Manual</a></td><td ><a href="qtdesigner-module.html">C++ Classes</a></td><td >QExtensionFactory</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtdesigner-manual.html">Qt 5.14.2 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#reimplemented-public-functions">Reimplemented Public Functions</a></li>
<li class="level1"><a href="#protected-functions">Protected Functions</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QExtensionFactory Class</h1>
<!-- $$$QExtensionFactory-brief -->
<p>The QExtensionFactory class allows you to create a factory that is able to make instances of custom extensions in Qt Designer. <a href="#details">More...</a></p>
<!-- @@@QExtensionFactory -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QExtensionFactory&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += designer</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="../qtcore/qobject.html">QObject</a> and <a href="qabstractextensionfactory.html">QAbstractExtensionFactory</a></td></tr></table></div><ul>
<li><a href="qextensionfactory-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qextensionfactory.html#QExtensionFactory">QExtensionFactory</a></b>(QExtensionManager *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QExtensionManager *</td><td class="memItemRight bottomAlign"><b><a href="qextensionfactory.html#extensionManager">extensionManager</a></b>() const</td></tr>
</table></div>
<a name="reimplemented-public-functions"></a>
<h2 id="reimplemented-public-functions">Reimplemented Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> virtual QObject *</td><td class="memItemRight bottomAlign"><b><a href="qextensionfactory.html#extension">extension</a></b>(QObject *<i>object</i>, const QString &amp;<i>iid</i>) const override</td></tr>
</table></div>
<a name="protected-functions"></a>
<h2 id="protected-functions">Protected Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> virtual QObject *</td><td class="memItemRight bottomAlign"><b><a href="qextensionfactory.html#createExtension">createExtension</a></b>(QObject *<i>object</i>, const QString &amp;<i>iid</i>, QObject *<i>parent</i>) const</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QExtensionFactory-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>In <i>Qt Designer</i> the extensions are not created until they are required. For that reason, when implementing a custom extension, you must also create a QExtensionFactory, i.e&#x2e; a class that is able to make an instance of your extension, and register it using <i>Qt Designer</i>'s <a href="qextensionmanager.html">extension manager</a>.</p>
<p>The <a href="qextensionmanager.html">QExtensionManager</a> class provides extension management facilities for Qt Designer. When an extension is required, Qt Designer's <a href="qextensionmanager.html">extension manager</a> will run through all its registered factories calling <a href="qextensionfactory.html#createExtension">QExtensionFactory::createExtension</a>() for each until the first one that is able to create a requested extension for the selected object, is found. This factory will then make an instance of the extension.</p>
<p>There are four available types of extensions in Qt Designer: <a href="qdesignercontainerextension.html">QDesignerContainerExtension</a> , <a href="qdesignermembersheetextension.html">QDesignerMemberSheetExtension</a>, <a href="qdesignerpropertysheetextension.html">QDesignerPropertySheetExtension</a> and <a href="qdesignertaskmenuextension.html">QDesignerTaskMenuExtension</a>. Qt Designer's behavior is the same whether the requested extension is associated with a multi page container, a member sheet, a property sheet or a task menu.</p>
<p>You can either create a new QExtensionFactory and reimplement the <a href="qextensionfactory.html#createExtension">QExtensionFactory::createExtension</a>() function. For example:</p>
<pre class="cpp">

          <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> <span class="operator">*</span>ANewExtensionFactory<span class="operator">::</span>createExtension(<span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> <span class="operator">*</span>object<span class="operator">,</span>
                  <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>iid<span class="operator">,</span> <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> <span class="operator">*</span>parent) <span class="keyword">const</span>
          {
              <span class="keyword">if</span> (iid <span class="operator">!</span><span class="operator">=</span> Q_TYPEID(<span class="type"><a href="qdesignercontainerextension.html">QDesignerContainerExtension</a></span>))
                  <span class="keyword">return</span> <span class="number">0</span>;

              <span class="keyword">if</span> (MyCustomWidget <span class="operator">*</span>widget <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span>MyCustomWidget<span class="operator">*</span><span class="operator">&gt;</span>
                     (object))
                  <span class="keyword">return</span> <span class="keyword">new</span> MyContainerExtension(widget<span class="operator">,</span> parent);

              <span class="keyword">return</span> <span class="number">0</span>;
          }

</pre>
<p>Or you can use an existing factory, expanding the <a href="qextensionfactory.html#createExtension">QExtensionFactory::createExtension</a>() function to make the factory able to create your extension as well. For example:</p>
<pre class="cpp">

          <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> <span class="operator">*</span>AGeneralExtensionFactory<span class="operator">::</span>createExtension(<span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> <span class="operator">*</span>object<span class="operator">,</span>
                  <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>iid<span class="operator">,</span> <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> <span class="operator">*</span>parent) <span class="keyword">const</span>
          {
              MyCustomWidget <span class="operator">*</span>widget <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span>MyCustomWidget<span class="operator">*</span><span class="operator">&gt;</span>(object);

              <span class="keyword">if</span> (widget <span class="operator">&amp;</span><span class="operator">&amp;</span> (iid <span class="operator">=</span><span class="operator">=</span> Q_TYPEID(<span class="type"><a href="qdesignertaskmenuextension.html">QDesignerTaskMenuExtension</a></span>))) {
                  <span class="keyword">return</span> <span class="keyword">new</span> MyTaskMenuExtension(widget<span class="operator">,</span> parent);

              } <span class="keyword">else</span> <span class="keyword">if</span> (widget <span class="operator">&amp;</span><span class="operator">&amp;</span> (iid <span class="operator">=</span><span class="operator">=</span> Q_TYPEID(<span class="type"><a href="qdesignercontainerextension.html">QDesignerContainerExtension</a></span>))) {
                  <span class="keyword">return</span> <span class="keyword">new</span> MyContainerExtension(widget<span class="operator">,</span> parent);

              } <span class="keyword">else</span> {
                  <span class="keyword">return</span> <span class="number">0</span>;
              }
          }

</pre>
<p>For a complete example using the QExtensionFactory class, see the <a href="qtdesigner-taskmenuextension-example.html">Task Menu Extension example</a>. The example shows how to create a custom widget plugin for Qt Designer, and how to to use the <a href="qdesignertaskmenuextension.html">QDesignerTaskMenuExtension</a> class to add custom items to Qt Designer's task menu.</p>
</div>
<p><b>See also </b><a href="qextensionmanager.html">QExtensionManager</a> and <a href="qabstractextensionfactory.html">QAbstractExtensionFactory</a>.</p>
<!-- @@@QExtensionFactory -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QExtensionFactory[overload1]$$$QExtensionFactoryQExtensionManager* -->
<h3 class="fn" id="QExtensionFactory"><a name="QExtensionFactory"></a>QExtensionFactory::<span class="name">QExtensionFactory</span>(<span class="type"><a href="qextensionmanager.html">QExtensionManager</a></span> *<i>parent</i> = nullptr)</h3>
<p>Constructs an extension factory with the given <i>parent</i>.</p>
<!-- @@@QExtensionFactory -->
<!-- $$$createExtension[overload1]$$$createExtensionQObject*constQString&QObject* -->
<h3 class="fn" id="createExtension"><a name="createExtension"></a><code>[virtual protected] </code><span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *QExtensionFactory::<span class="name">createExtension</span>(<span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>object</i>, const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>iid</i>, <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>parent</i>) const</h3>
<p>Creates an extension specified by <i>iid</i> for the given <i>object</i>. The extension object is created as a child of the specified <i>parent</i>.</p>
<p><b>See also </b><a href="qextensionfactory.html#extension">extension</a>().</p>
<!-- @@@createExtension -->
<!-- $$$extension[overload1]$$$extensionQObject*constQString& -->
<h3 class="fn" id="extension"><a name="extension"></a><code>[override virtual] </code><span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *QExtensionFactory::<span class="name">extension</span>(<span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>object</i>, const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>iid</i>) const</h3>
<p>Reimplements: <a href="qabstractextensionfactory.html#extension">QAbstractExtensionFactory::extension</a>(QObject *object, const QString &amp;iid) const.</p>
<p>Returns the extension specified by <i>iid</i> for the given <i>object</i>.</p>
<p><b>See also </b><a href="qextensionfactory.html#createExtension">createExtension</a>().</p>
<!-- @@@extension -->
<!-- $$$extensionManager[overload1]$$$extensionManager -->
<h3 class="fn" id="extensionManager"><a name="extensionManager"></a><span class="type"><a href="qextensionmanager.html">QExtensionManager</a></span> *QExtensionFactory::<span class="name">extensionManager</span>() const</h3>
<p>Returns the extension manager for the extension factory.</p>
<!-- @@@extensionManager -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
